package pe.com.market.emarket.action;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import pe.com.market.common.util.Utilitario;
import pe.com.market.emarket.model.Product;

public class DeleteProductAction {
	private int id;
	private String message;
	
	public String execute(){
		EntityManager em=Utilitario.getInstance().getEntityManager();
		EntityTransaction tx=em.getTransaction();
		String camino="success";
		try{
			tx.begin();
			Product product =em.find(Product.class, id);
			em.remove(product);
			tx.commit();
			message="The product was removed successfully";
		}catch(Exception ex){
			ex.printStackTrace();
			message="Unsuccessful Delete";
			camino="error";
			tx.rollback();
		}
		return camino;
	}


	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}
	
}